package cn.cs.service.impl;

import cn.cs.client.AgentTypeClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.AgentType;
import cn.cs.service.AgentTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AgentTypeServiceImpl implements AgentTypeService {

    @Resource
    private AgentTypeClient agentTypeClient;

    public AgentType getAgentTypeById(String id) throws Exception {
        return agentTypeClient.getAgentTypeById(id);
    }

    public List<AgentType> getAgentTypeListByMap(Map<String, Object> param) throws Exception {
        return agentTypeClient.getAgentTypeListByMap(param);
    }

    public Integer getAgentTypeCountByMap(Map<String, Object> param) throws Exception {
        return agentTypeClient.getAgentTypeCountByMap(param);
    }

    public Integer addAgentType(AgentType agentType) throws Exception {
        return agentTypeClient.addAgentType(agentType);
    }

    public Integer modifyAgentType(AgentType agentType) throws Exception {
        return agentTypeClient.modifyAgentType(agentType);
    }

    public Integer deleteAgentTypeById(String id) throws Exception {
        return agentTypeClient.deleteAgentTypeById(id);
    }

    public Page<AgentType> queryAgentTypePageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = agentTypeClient.getAgentTypeCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<AgentType> agentTypeList = agentTypeClient.getAgentTypeListByMap(param);
        page.setRows(agentTypeList);
        return page;
    }

}
